#include <stdio.h>

typedef struct tv_name
{
    char name1[16];
    char name2[16];
    char code[32];
} TV_NAME;

TV_NAME cctv[] = {
    {"CCTV1", "CCTV-1", "3221225642"},
    {"CCTV2", "CCTV-2", "3221225643"},
    {"CCTV3", "CCTV-3", "3221225634"},
    {"CCTV4", "CCTV-4", "3221225621"},
    {"CCTV5", "CCTV-5", "3221225633"},
    {"CCTV5+", "CCTV-5+", "3221225706"},
    {"CCTV6", "CCTV-6", "3221225632"},
    {"CCTV7", "CCTV-7", "3221225624"},
    {"CCTV8", "CCTV-8", "3221225631"},
    {"CCTV9", "CCTV-9", "3221225646"},
    {"CCTV10", "CCTV-10", "3221225636"},
    {"CCTV11", "CCTV-11", "3221225628"},
    {"CCTV12", "CCTV-12", "3221225629"},
    {"CCTV13", "CCTV-13", "3221225638"},
    {"CCTV14", "CCTV-14", "3221225639"},
    {"CCTV15", "CCTV-15", "3221225641"},
    {"CCTV17", "CCTV-17", "3221225907"},
};

typedef struct tv_ip
{
    char text[16];
} TV_IP,TV_GROUP,TV_PORT;


TV_IP ip[] = {
    "39.135.138.58",
    "39.135.138.59",
    "39.135.138.60"
};

TV_GROUP group[] = {
    "PLTV",
    "TVOD",
};

TV_PORT port[] = {
    "88888888",
    "88888910",
};


TV_NAME wstv[] = {
    {"湖南卫视", "HN", "3221225704"},
    {"江苏卫视", "JS", "3221225702"},
    {"浙江卫视", "ZJ", "3221225703"},
    {"东方卫视", "DF", "3221225658"},
};

int main(int argc, char **argv)
{
    char data[256];

    FILE* fp = fopen("test.m3u","wb");
    if( NULL == fp){
        return;
    }


    // 央视
    for (int i = 0; i < sizeof(cctv) / sizeof(TV_NAME); i++)
    {
        fprintf(fp, "#EXTINF:-1 ,%s\n", cctv[i].name1);
        fprintf(fp, "http://111.63.117.13:6060/030000001000/%s/%s.m3u8\n", cctv[i].name2, cctv[i].name2);
        fprintf(fp, "#EXTINF:-1 ,%s\n", cctv[i].name1);
        fprintf(fp, "http://39.134.115.163:8080/PLTV/88888910/224/%d/index.m3u8\n", cctv[i].code);
        for (int j = 0; j < sizeof(ip) / sizeof(TV_IP); j++)
        {
            for (int k = 0; k < sizeof(group) / sizeof(TV_GROUP); k++)
            {
                for (int l = 0; l < sizeof(port) / sizeof(TV_PORT); l++)
                {
                    fprintf(fp, "#EXTINF:-1 ,%s\n", cctv[i].name1);
                    fprintf(fp, "http://%s:18890/%s/%s/224/%s/index.m3u8\n", 
                    ip[j].text, group[k].text, port[l].text, cctv[i].code);
                }
            }
        }
    }

    // 卫视
    for (int i = 0; i < sizeof(wstv) / sizeof(TV_NAME); i++)
    {
        fprintf(fp, "#EXTINF:-1 ,%s\n", wstv[i].name1);
        fprintf(fp, "http://hwrr.jx.chinamobile.com:8080/PLTV/88888888/224/%s/index.m3u8\n", wstv[i].code);
        fprintf(fp, "#EXTINF:-1 ,%s\n", wstv[i].name1);
        fprintf(fp, "http://39.134.115.163:8080/PLTV/88888910/224/%s/index.m3u8\n", wstv[i].code);
    }

    fclose(fp);
    return 0;
}
